#include "gaussianblur.h"

GaussianBlur::GaussianBlur()
{
    k_rows=3;
    k_cols=3;
    kernel=new double[k_rows*k_cols];
    //for(i=0;i<k_rows*k_cols;i++)
      //  kernel[i]=.04;
    kernel[0]=.0625;
    kernel[1]=.125;
    kernel[2]=.0625;
    kernel[3]=.125;
    kernel[4]=.25;
    kernel[5]=.125;
    kernel[6]=.0625;
    kernel[7]=.125;
    kernel[8]=.0625;
}

void GaussianBlur::setKernel(double *kernel,int k_rows,int k_cols){
    this->k_rows=k_rows;
    this->k_cols=k_cols;
    this->kernel=kernel;
}

void GaussianBlur::gaussian(double radius, double *array){
    int size=radius*2+1;
    int i,j;
    i=0;
    for(int x=-radius;x<=radius;x++){
        j=0;
        for(int y=-radius;y<=radius;y++){
            array[j+i*size]=(1.0/(2*3.14*radius))*exp(-(x*x+y*y)/(2.0*radius*radius));
       //     cout<<array[j+i*size];
            j++;
        }
        i++;
     //   cout<<endl;
    }


}
void GaussianBlur::gaussian(double radius, double *array,int rows,int cols){
    int size=rows*cols;
    array=new double[size];
    int i,j;
    i=0;
    cout<<"For sigma "<<radius<<"and size "<<size<<endl;
    for(int x=-(cols/2);x<=cols/2;x++){
        j=0;
        for(int y=-rows/2;y<=rows/2;y++){
            array[j+i*size]=(1.0/(2*3.14*radius))*exp(-(x*x+y*y)/(2.0*radius*radius));
            cout<<array[j+i*size];
            j++;
        }
        i++;
      cout<<endl;
    }
}

GaussianBlur::~GaussianBlur(){
    delete [] kernel;

}
